package TAIC.IPLM;

import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;

public class CompleteCor {

	/**
	 * @param args
	 * This program is used for old CodeBookGen to complete the corresponding position information 
	 * that lacked in the correspondence file of randomly selected CodeBook
	 */
	public static void main(String[] args) throws Exception 	{
		if ( args.length != 2 ) {
			System.out.println ( "please input the corresponing file and output file"  ); 
			return ;  
		}
		Scanner scanner = new Scanner ( new File ( args [ 0 ] )) ;
		PrintStream fout = new PrintStream ( new File ( args [ 1 ] )) ;  
		String lastFile = "" ;
		Scanner fileScanner = null ;
		int curPos = 0 ; 
		while ( scanner.hasNext ()  ) {
			String thisFile = scanner.next() ;
			int pos = scanner.nextInt() ;
			fout.print( thisFile + " " + pos ) ; 
			if ( ! thisFile.equals( lastFile )) {
				if ( fileScanner != null ) fileScanner.close() ; 
				fileScanner = new Scanner ( new File ( thisFile)) ;
				fileScanner.nextLine() ; 
				lastFile = thisFile ;
				curPos = 0 ; 
			}
			for ( ; curPos < pos ; curPos ++ ) fileScanner.nextLine() ;
			for ( int i = 0 ; i < 4 ; i ++ 	) fout.print ( " " + fileScanner.next() ) ;
			fout.println () ;
		}
		fout.close() ; 
	}

}
 